home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10750 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: airdmhor.gen.nz!not-for-mail
  2. From: gumboot@airdmhor.gen.nz (Simon Hosie)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Determining the length of an int in string form
  5. Date: 20 Mar 1996 07:21:46 +1200
  6. Organization: Airdmhor : a couple of BBS's, a bunch of people, and a cat.
  7. Message-ID: <4in1ga$ogk@airdmhor.gen.nz>
  8. References: <3146D058.DD7@cbm.com> <4i7uth$qph@inet-nntp-gw-1.us.oracle.com> <DoE38u.GIH@iquest.net>
  9. NNTP-Posting-Host: airdmhor.gen.nz
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. wkaufman@wkaufman.us.oracle.com (William Kaufman) wrote:
  13. +In article <3146D058.DD7@cbm.com> Dave Payne <paynedc@cbm.com> writes:
  14. +] Consider this:
  15. +]
  16. +] I have a variable of type int, and I would like to use the sprintf()
  17. +] function to write this variable to a string.  However, I want to
  18. +] dynamically allocate the space for the string, and only malloc enough
  19. +] space to hold the int.
  20.  
  21. Doug & Rose Miller:
  22. > WHY ???
  23. > Even a 32-bit int is only 9 characters at most, and that's *with* the sign.  Why not just declare
  24. > a string and be done with it?  Is storage space that tight for you, that nine bytes matters?
  25.  
  26.   That's wrong straight off, 2 ^ 31 is 2147483648 which is 10 characters
  27. (unless you mean in hex), then there's another character for the sign.  Then
  28. lots and lots more characters if the int is more than 32 bits.
  29.  
  30.  
  31.   Darn it!  That's my clock radio trying to wake me up - I'd better go to
  32. bed soon.
  33.